<div class="map">
  <el-breadcrumb class="bread" separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户列表</el-breadcrumb-item>
  </el-breadcrumb>

  <!-- 搜索 -->
  <el-row :gutter="20">
    <el-col :span="8">
      <el-input placeholder="请输入内容" v-model="searchText">
        <el-button
          @click="startSearch"
          slot="append"
          icon="el-icon-search"
        ></el-button>
      </el-input>
    </el-col>
    <el-col :span="3">
      <el-button @click="alertAddUserDialog">添加用户</el-button>
    </el-col>
  </el-row>

  <!-- 表格 -->
  <!--
    el-table : 表格
     :data  要显示的数据 (数组) 数组有几个元素就有几行
    el-table-column : 列
      prop : 内容字段名, 负责显示内容
      label : 标题
      width : 宽度

   -->
  <el-table :data="userList" style="width: 100%">
    <el-table-column prop="username" label="姓名" width="180">
    </el-table-column>
    <el-table-column prop="email" label="邮箱" width="180"> </el-table-column>
    <el-table-column prop="mobile" label="电话"> </el-table-column>
    <el-table-column prop="mg_state" label="用户状态">
      <template slot-scope="scope">
        <!-- el-switch 中的v-model 应该绑定当前数据中的 mg-state -->
        <!-- 但是 v-modal 应该绑定 data中的数据 -->
        <!-- 注意 : 通过 scope.row 可以获取当前行的数据, scope.row.mg_state 获取当前用户状态 -->

        <el-switch
          @change="changeUserState(scope.row)"
          v-model="scope.row.mg_state"
        ></el-switch>
      </template>
    </el-table-column>
    <el-table-column prop="address" label="操作">
      <template slot-scope="scope">
        <el-button
          @click="showUserEditDialog(scope.row)"
          type="primary"
          plain
          size="mini"
          icon="el-icon-edit"
        ></el-button>
        <el-button
          @click="delUser(scope.row.id)"
          type="danger"
          icon="el-icon-delete"
          plain
          size="mini"
        ></el-button>
        <el-button
          type="success"
          icon="el-icon-check"
          plain
          @click="showRolesDialog(scope.row)"
          >分配角色</el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页 -->
  <el-pagination
    background
    layout="prev, pager, next"
    :page-size="pageSize"
    :total="total"
    :current-page="pageNum"
    @current-change="changCurrent"
  >
  </el-pagination>

  <!-- 添加用户 对话框 -->
  <el-dialog
    title="添加用户"
    :visible.sync="dialogFormVisible"
    @close="closeDialog"
  >
    <!-- addUserForm 是数据对象 -->
    <el-form
      :model="addUserForm"
      label-width="100px"
      :rules="rules"
      ref="addUserForm"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="addUserForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="addUserForm.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="addUserForm.email"></el-input>
      </el-form-item>
      <el-form-item label="手机" prop="mobile">
        <el-input v-model="addUserForm.mobile"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="addUser">确 定</el-button>
    </div>
  </el-dialog>

  <!-- 编辑对话框 -->
  <el-dialog title="编辑用户" :visible.sync="dialogEditFormVisible">
    <el-form
      :model="userEditForm"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="用户名" prop="username">
        <!-- <el-input v-model="userEditForm.username"></el-input> -->
        <el-tag type="info">{{ userEditForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="userEditForm.email"></el-input>
      </el-form-item>
      <el-form-item label="电话" prop="mobile">
        <el-input v-model="userEditForm.mobile"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogEditFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="editUser">确 定</el-button>
    </div>
  </el-dialog>

  <!-- 分配角色对话 -->
  <el-dialog title="分配角色" :visible.sync="dialogRolesFormVisible">
    <el-form :model="Rolesform" label-width="80px">
      <el-form-item label="用户名">
        <!-- <el-input v-model="Rolesform.username" ></el-input> -->
        <el-tag>{{ Rolesform.username }}</el-tag>
      </el-form-item>
      <el-form-item label="角色列表">
        <el-select v-model="Rolesform.rid" placeholder="请选择活动区域">
          <el-option
            v-for="item in rolesList"
            :key="item.id"
            :label="item.roleName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogRolesFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="selectedRoles">确 定</el-button>
    </div>
  </el-dialog>
</div>
